

#ifndef _PLUGIN_RENDER_H_
#define _PLUGIN_RENDER_H_

#include <ace/xcomponent/native_interface_xcomponent.h>
#include <napi/native_api.h>
#include <string>
#include <unordered_map>

#include "egl_core.h"

class PluginRender {
  public:
    PluginRender(std::string &id);
    static PluginRender *GetInstance(std::string &id);
    static OH_NativeXComponent_Callback *GetNXComponentCallback();

    void SetNativeXComponent(OH_NativeXComponent *component);

  public:
    // NAPI接口
    napi_value Export(napi_env env, napi_value exports);

    // NAPI向JS提供
    static napi_value NapiDrawCube(napi_env env, napi_callback_info info);
    static napi_value setTexture(napi_env env, napi_callback_info info);

    // 回调，由ACE XComponent调用
    void OnSurfaceCreated(OH_NativeXComponent *component, void *window);

    void OnSurfaceChanged(OH_NativeXComponent *component, void *window);

    void OnSurfaceDestroyed(OH_NativeXComponent *component, void *window);

    void DispatchTouchEvent(OH_NativeXComponent *component, void *window);

  public:
    static std::unordered_map<std::string, PluginRender *> instance_;
    static OH_NativeXComponent_Callback callback_;

    OH_NativeXComponent *component_;
    EGLCore *eglCore_;
    pthread_t tid_;

    std::string id_;
    uint64_t width_;
    uint64_t height_;

    double x_;
    double y_;
    OH_NativeXComponent_TouchEvent touchInfo_;
};

#endif // _PLUGIN_RENDER_H_
